package com.demo.webapp.validator.adapter;

import java.util.Map;

import com.opensymphony.xwork2.validator.FieldValidator;

/**
 * 验证适配器
 * 将不同的验证器转化成对应的前点js验证字符串
 * @author ryuu.kk
 *
 */
public interface ValidateAdapter {

	/**
	 * 将FieldValidator转换为TransWrapper对象模型
	 * @param fV FieldValidator
	 * @return TransWrapper
	 */
	TransWrapper convert(FieldValidator fV);
	
	/**
	 * 当前验证是配置是否支持参数FieldValidator
	 * @param fV FieldValidator
	 * @return boolean
	 */
	boolean support(FieldValidator fV);
	
	/**
	 * 验证转换器封装对象
	 * 该对象由ValidateAdapter创建,并最终被处理成js验证内容
	 * @author ryuu.kk
	 */
	public class TransWrapper {
		
		/**
		 * js前端验证类型
		 * required、email等
		 */
		private String key;
		
		/**
		 * 转换器类型
		 */
		private String type;
		
		/**
		 * 转换器最终消息
		 */
		private String message;
		
		/**
		 * 验证字符串
		 */
		private String validation;
		
		/**
		 * 验证扩展Map
		 */
		private Map<String, Object> extendMap;
		
		public String getKey() {
			return key;
		}
		public void setKey(String key) {
			this.key = key;
		}
		public String getType() {
			return type;
		}
		public void setType(String type) {
			this.type = type;
		}
		public String getMessage() {
			return message;
		}
		public void setMessage(String message) {
			this.message = message;
		}
		public String getValidation() {
			return validation;
		}
		public void setValidation(String validation) {
			this.validation = validation;
		}
		public Map<String, Object> getExtendMap() {
			return extendMap;
		}
		public void setExtendMap(Map<String, Object> extendMap) {
			this.extendMap = extendMap;
		}
	}
}
